package com.zb.order.controller;


import com.zb.annotation.SystemLog;
import com.zb.constant.OperationLogModuleType;
import com.zb.constant.OperationLogType;
import com.zb.entity.AccounLoginInfo;
import com.zb.order.service.ConWorkFeeService;
import com.zb.result.PageUtil;
import com.zb.result.Result;
import com.zb.service.ZjWorkFeeDetailService;
import com.zb.service.ZjWorkFeeLogService;
import com.zb.service.ZjWorkFeeService;
import com.zb.utils.TokenUtil;
import com.zb.vo.OrderFeeCheckVo;
import com.zb.vo.OrderFeeListSelectVo;
import com.zb.vo.WorkFeeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * <p>
 * 工单费用表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2023-10-25
 */
@Api(tags = "工单服务费用项目类接口")
@RestController
@RequestMapping("/work/fee")
public class ZjWorkFeeController {
    @Resource
    private ConWorkFeeService conWorkFeeService;
    @Resource
    private ZjWorkFeeService workFeeService;
    @Resource
    private ZjWorkFeeDetailService workFeeDetailService;
    @Resource
    private ZjWorkFeeLogService workFeeLogService;

    @SystemLog(moduleType = OperationLogModuleType.WORK_ORDER_TYPE, type = OperationLogType.INSERT_UPDATE, remark = "服务工单-费用管理/工单详情 - 保存或修改工单服务费用")
    @ApiOperation("保存或修改工单服务费用")
    @PostMapping("/save")
    public Result save(HttpServletRequest request, @RequestBody @Valid WorkFeeVo workFeeVo) {
        AccounLoginInfo loginInfo = TokenUtil.getAccountLoginInfo(request);
        conWorkFeeService.save(loginInfo, workFeeVo);
        return Result.success(null == workFeeVo.getId()? "新增工单服务费用成功" : "修改工单服务费用成功");
    }

    @ApiOperation("获取工单服务费用项目列表")
    @PostMapping("getList")
    public Result getList(HttpServletRequest request, @RequestBody @Valid OrderFeeListSelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success("获取工单服务费用项目列表成功").data(conWorkFeeService.getList(custAccId, selectVo));
    }

    @ApiOperation("根据工单ID获取服务项目列表")
    @PostMapping("/getOrderDetailFeeProjectList/{workId}")
    public Result getOrderDetailFeeProjectList(@PathVariable @ApiParam(value = "工单ID", required = true) Long workId, @RequestBody PageUtil pageUtil) {
        return Result.success("获取服务项目列表成功").data(workFeeService.getOrderDetailFeeProjectList(workId, pageUtil));
    }

    @ApiOperation("根据服务项目ID获取服务项目详情")
    @GetMapping("/getOrderFeeDetail/{id}")
    public Result getOrderFeeDetail(@PathVariable @ApiParam(value = "服务项目ID", required = true) Long id) {
        return Result.success("获取工单服务费用项目详情成功").data("row", workFeeService.getOrderFeeDetail(id));
    }

    @ApiOperation("根据服务项目ID获取项目信息列表")
    @GetMapping("/getOrderFeeDetailProjectInfo/{id}")
    public Result getOrderFeeDetailProjectInfo(@PathVariable @ApiParam(value = "服务项目ID", required = true) Long id) {
        return Result.success("获取服务费用项目详情的项目信息成功").data("row", workFeeDetailService.getOrderFeeDetailProjectInfo(id));
    }

    @ApiOperation("根据服务项目ID获取服费用项目日志列表")
    @PostMapping("/getOrderFeeLogList/{id}")
    public Result getOrderFeeLogList(@PathVariable @ApiParam(value = "服务项目ID", required = true) Long id, @RequestBody PageUtil pageUtil) {
        return Result.success("获取服务费用项目日志记录列表成功").data(workFeeLogService.getOrderFeeLogList(id, pageUtil));
    }


    @SystemLog(moduleType = OperationLogModuleType.WORK_ORDER_TYPE, type = OperationLogType.UPDATE, remark = "服务工单-费用管理/工单详情 - 保存或修改工单服务费用")
    @ApiOperation("审核工单服务费用项目")
    @PostMapping("/checkOrderFee")
    public Result checkOrderFee(HttpServletRequest request, @RequestBody @Valid OrderFeeCheckVo orderFeeCheckVo) {
        AccounLoginInfo loginInfo = TokenUtil.getAccountLoginInfo(request);
        conWorkFeeService.checkOrderFee(loginInfo, orderFeeCheckVo);
        return Result.success("工单服务费用项目审核成功");
    }

}
